package ru.dc.object.commands;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <pre>
 * User: Penkov Vladimir
 * Date: 08.10.2010
 * Time: 18:10:31
 * </pre>
 */
public class ChatCommand extends Command {

    private String nick;
    private String text;

    @Override
    public void parseCommand() {
        int startNickIndex = 1;
        final String cmd = getCommand();
        int endNickIndex = cmd.indexOf(">", startNickIndex);
        setNick(cmd.substring(startNickIndex, endNickIndex));

        final int startTextIndex = endNickIndex + 2;
        if (cmd.length()> startTextIndex+1) {
            setText(cmd.substring(startTextIndex));
        }
        else {
            setText(null);
        }
    }

    @Override
    public String generateCommand() {
        return "<"+getNick()+"> "+getText();
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getNick() {
        return nick;
    }

    public void setNick(String nick) {
        this.nick = nick;
    }

    @Override
    public String toString() {
        return "ChatCommand{" +
                "nick='" + nick + '\'' +
                ", text='" + text + '\'' +
                '}';
    }
}
